<?php

namespace app\adminapi\controller\v1\activity;

use app\adminapi\controller\AuthController;
use app\services\activity\ActivityCategoryService;
use think\facade\App;

class ActivityCategory extends AuthController
{
    protected $service;

    public function __construct(App $app, ActivityCategoryService $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }


    public function index()
    {
        $data = $this->service->getList();
        return app('json')->success($data);
    }

    public function save($id)
    {
        $data = $this->request->postMore([
            ['cate_name', ''],
            ['pid', 0],
        ]);
        $this->service->save($id, $data);
        return app('json')->success(100021);
    }

    /**
     * 设置批量活动分类上架
     * @return mixed
     */
    public function show()
    {
        [$ids] = $this->request->postMore([
            ['ids', []]
        ], true);
        $this->service->setShow($ids, 1);
        return app('json')->success(100014);
    }

    /**
     * 设置批量活动分类下架
     * @return mixed
     */
    public function unshow()
    {
        [$ids] = $this->request->postMore([
            ['ids', []]
        ], true);
        $this->service->setShow($ids, 0);
        return app('json')->success(100014);
    }

    public function delete($id)
    {
        $this->service->delete($id);
        return app('json')->success(100002);
    }
}